package com.wgj.android.dialog;

import android.app.Dialog;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;

import com.jiaai.xui.view.widget.XAlertMsgDialog;
import com.wgj.android.R;
import com.wgj.android.accesslibility.config.WXConfginUtil;
import com.wgj.android.accesslibility.service.WGJAccessServier;
import com.wgj.android.permission.WindowManagerPermission;

import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/12/29.
 */


public class WindowPermissionTipsDialog extends AppCompatDialogFragment {
    private Dialog dialog;
    private View view;
    private  OnNextCallback callback;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        if (view == null){
            super.onCreate(savedInstanceState);
            view = LayoutInflater.from(getActivity()).inflate(R.layout.window_permission_tips_dialog, null, false);
        }
        ButterKnife.bind(this,view);

    }

    @OnCheckedChanged(R.id.checkbox)
    public  void onChanged(CompoundButton button, boolean b){
        WXConfginUtil.setIsNotTipsWindowPermission(getContext(),b);
    }
    @OnClick(R.id.nexBut)
    public  void  onClick(View view){
            if(callback!=null){
                callback.onNext();
            }
          dismiss();
    }

    public WindowPermissionTipsDialog setCallback(OnNextCallback callback) {
        this.callback = callback;
        return this;
    }

    @OnClick(R.id.closeBut)
    public  void  onCloseButClick(View view){
        dismiss();
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        super.onCreateDialog(savedInstanceState);
        if(dialog==null){
            // 使用不带Theme的构造器, 获得的dialog边框距离屏幕仍有几毫米的缝隙。
            initDialogStyle(view);
        }
        return dialog;
    }

    private void initDialogStyle(View view) {
        dialog = new Dialog(getActivity(), R.style.dialog_setting);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(true); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window window = dialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.CENTER; // 紧贴底部
        lp.width =WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }


    public  interface  OnNextCallback{
        public  void  onNext();
    }
}
